﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using BEGDC.CC.Web.UserControls;
using BEGDC.CC.BL.CCFlow.CR;
using BEGDC.CC.Entity;
using BEGDC.CC.BL.Workflow;
using BEGDC.CC.BL.Common;
using BEGDC.CC.BL.Common.Query;
using BEGDC.Utility.Castle;

namespace BEGDC.CC.Web.Common
{
    /// <summary>
    /// ApplicationDetails 的摘要说明。
    /// </summary>
    public class ApplicationDetails : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.DataGrid dgAppList;

        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Page.Request.QueryString["CustomerName"] != String.Empty)
                {
                    //System.Web.HttpUtility.UrlDecode(str, System.Text.Encoding.Unicode);
                    //System.Web.HttpUtility.UrlDecode(str, System.Text.Encoding.UTF8);
                    //System.Web.HttpUtility.UrlDecode(str, System.Text.Encoding.GetEncoding("GB2312 ")); 
                    //string customerName = System.Web.HttpUtility.UrlDecode(Request.QueryString["CustomerName"].Replace("_", " "), System.Text.Encoding.UTF8);
                    // string companyName = System.Web.HttpUtility.UrlDecode(Request.QueryString["CustomerName"].Replace("_", " "), System.Text.Encoding.UTF8);
                    FillApplicationInfo(HttpUtility.UrlDecode(Request.QueryString["CustomerName"].Replace("_", " ")), HttpUtility.UrlDecode(Request.QueryString["CompanyName"].Replace("_", " ")));
                }

                //				if(Session["Attendee_CustomerName"] != null)
                //				{
                //					this.FillApplicationInfo(Session["Attendee_CustomerName"].ToString(),Session["Attendee_CustomerCompany"].ToString());
                //				}
            }
        }

        #region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.dgAppList.ItemDataBound += new DataGridItemEventHandler(dgAppList_ItemDataBound);
            this.Load += new System.EventHandler(this.Page_Load);

        }

        void dgAppList_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.Cells[1].Text == "OCR")
                e.Item.Cells[1].Text = "IBGCR";
            if (e.Item.Cells[1].Text == "OCV")
                e.Item.Cells[1].Text = "IBGCV";
            if (e.Item.Cells[0].Text.ToString().EndsWith("-B"))
            {
                string appNo = e.Item.Cells[0].Text.ToString();
                e.Item.Cells[0].Text = appNo.Substring(0, appNo.LastIndexOf("-B"));
            }
        }

        #endregion

        private void FillApplicationInfo(string customerName, string companyName)
        {
            IQuery QueryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
            this.dgAppList.DataSource = QueryService.GetCustomerAttendeeAppForOversea(customerName, companyName);
            this.dgAppList.DataBind();
        }

        private void dgAppList_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
        {

        }
    }
}
